<%--
 * (c)2010-2012 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 *
--%>

<%@ include file="./init.jsp" %>

<%-- use our pagedListHolder --%>
<jsp:useBean id="pagedListHolder" scope="request" 
   type="org.springframework.beans.support.PagedListHolder"/>

<%--
 create link for pages, "~" will be replaced later on with the proper page 
 number
--%>
<portlet:renderURL var="pagedLink" portletMode="VIEW">
    <portlet:param name="action" value=""/>
    <portlet:param name="p" value="~"/>
</portlet:renderURL>

<h3><spring:message code="surveys.title"/></h3>

<div class="portlet-body">

<c:choose>
    <c:when test="${pagedListHolder.nrOfElements > 0}">
 
	<table class="lfr-table">

		<tr>
			<th><spring:message code="survey.label.name"/></th>
            <th><spring:message code="survey.label.start"/></th>
			<th><spring:message code="survey.label.expiration"/></th>
			<th><spring:message code="survey.label.status"/></th>
			<th></th>
		</tr>

		<c:forEach items="${pagedListHolder.pageList}" var="survey">
			<tr>
				<td><a href="<portlet:renderURL><portlet:param name="action" value="viewSurvey"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>">${survey.name}</a></td>
                <td align="right"><fmt:formatDate value="${survey.start}" dateStyle="medium" timeStyle="short" /></td>
				<td align="right"><fmt:formatDate value="${survey.expiration}" dateStyle="medium" timeStyle="short" /></td>
				<td align="right">${survey.status.translatedName}</td>
				<td>
					<a href="<portlet:renderURL><portlet:param name="action" value="showEditSurveyForm"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>"><img title="<spring:message code="survey.edit.button"/>" src="<html:imagesPath/>edit.png" border=0 /></a>
					<a href="<portlet:actionURL>
					           <portlet:param name="action" value="deleteSurvey"/>
					           <portlet:param name="surveyID" value="${survey.id}"/>
					         </portlet:actionURL>
					         " onclick="return confirm('<spring:message code="message.confirm.delete.survey"/>')">
					         <img title="<spring:message code="survey.delete.button"/>" src="<html:imagesPath/>delete.png" border=0 /></a>
                    <a href="<portlet:renderURL><portlet:param name="action" value="showExportReportForm"/><portlet:param name="surveyID" value="${survey.id}"/></portlet:renderURL>"><img title="<spring:message code="survey.export.button"/>" src="<html:imagesPath/>export.png" border=0 /></a>
				</td>
			</tr>
		</c:forEach>
	</table>
	
	</c:when>
	<c:otherwise>
	<spring:message code="message.noSurveys"/>.
	</c:otherwise>
</c:choose>

<%-- load our paging tag, pass pagedListHolder and the link --%>
<tg:paging pagedListHolder="${pagedListHolder}" pagedLink="${pagedLink}"/>

</div>

<div class="lfr-separator">&nbsp;</div>

<div class="lfr-toolbar">
    <a href="<portlet:renderURL><portlet:param name="action" value="showAddSurveyForm"/></portlet:renderURL>"><img title="<spring:message code="survey.add.button"/>" src="<html:imagesPath/>new.png" border=0 /></a>
</div>
